﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Pong_Project.Game_objects
{
    class AbstractFactory
    {
        private static Ball ball = new Ball(GameObjectIdentity.Ball, new Vector2(Game.WindowWidth / 2, Game.WindowHeight / 2), new Vector2(1.0f, 0.0f), 5.0f);
        private static Bat batLeft = new Bat(GameObjectIdentity.BatLeft, new Vector2(0, Game.WindowHeight / 2), new Vector2(0.0f, 1.0f), 6.0f);
        private static Bat batRight = new Bat(GameObjectIdentity.BatRight, new Vector2(Game.WindowWidth - 10, Game.WindowHeight / 2), new Vector2(0.0f, 1.0f), 6.0f);

        public static GameObject abstractFactory(string kind, Bat collectorIsBat, Ball collectorIsBall, Bat affectsBat, Ball affectsBall, GameObjectIdentity identity, int timeToLast, int timeToLive, int minTimeBeforeSpawning, int maxTimeBeforeSpawning, float scaleFactor, Vector2 directionModifyer)
        {
            if (kind == "powerup")
            {
                if (collectorIsBat == null)
                {
                    return new PowerupBall(identity, collectorIsBall, affectsBat, affectsBall, timeToLast, timeToLive, minTimeBeforeSpawning, maxTimeBeforeSpawning, scaleFactor, directionModifyer);
                }
                else // if bat
                {
                    return new PowerupBat(identity, collectorIsBat, affectsBat, affectsBall, timeToLast, timeToLive, minTimeBeforeSpawning, maxTimeBeforeSpawning, scaleFactor, directionModifyer);
                }
            }
            return null;
        }

        public static Ball Ball
        {
            get { return ball; }
        }

        public static Bat BatLeft
        {
            get { return batLeft; }
        }

        public static Bat BatRight
        {
            get { return batRight; }
        }

        public static Obstacle NewObject(float positionX, float positionY, float scaleX, float scaleY)
        {
            if (GameObjectManager.SpritesLoaded)
            {
                throw new InvalidOperationException("Adding new obstacles can only be done when initializing the game, before sprites are loaded.");
            }
            Obstacle obstacle = new Obstacle(GameObjectIdentity.Obstacle, new Vector2(positionX, positionY), ball);
            obstacle.ScaleX = scaleX;
            obstacle.ScaleY = scaleY;
            GameObjectManager.AddObstacle(obstacle);
            return obstacle;
        }
    }
}
